package com.atguigu.eduorder.service.impl;

import com.atguigu.commonutils.ordervo.CourseWebVoOrder;
import com.atguigu.commonutils.ordervo.UcenterMemberOrder;
import com.atguigu.eduorder.client.EduClient;
import com.atguigu.eduorder.client.UcenterClient;
import com.atguigu.eduorder.entity.TOrder;
import com.atguigu.eduorder.mapper.OrderMapper;
import com.atguigu.eduorder.service.OrderService;
import com.atguigu.eduorder.utils.OrderNoUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author shaki
 * @since 2021-06-25
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, TOrder> implements OrderService {
    @Resource
    private EduClient eduClient;
    @Resource
    private UcenterClient ucenterClient;
    
    @Override
    public String createOrders(String courseId, String memberId) {
        //通过远程调用获取用户信息
        UcenterMemberOrder userInfoOder = ucenterClient.getUserInfoOder(memberId);
        // 课程信息
        CourseWebVoOrder courseInfoOder = eduClient.getCourseInfoOder(courseId);
        TOrder order = new TOrder();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseId); //课程id
        order.setCourseTitle(courseInfoOder.getTitle());
        order.setCourseCover(courseInfoOder.getCover());
        order.setTeacherName(courseInfoOder.getTeacherName());
        order.setTotalFee(courseInfoOder.getPrice());
        order.setMemberId(memberId);
        order.setEmail(userInfoOder.getEmail());
        order.setNickname(userInfoOder.getNickname());
        order.setStatus(0);  //订单状态（0：未支付 1：已支付）
        order.setPayType(1);  //支付类型 ，微信1
        baseMapper.insert(order);
        //返回订单号luo
        return order.getOrderNo();
    }
}
